import numpy as np
import faiss


d = 128                            # dimension
nb = 10000                         # database size
np.random.seed(1234)             # make reproducible
xb = np.random.random((nb, d)).astype('float32')

index = faiss.IndexFlatL2(d)   # build the index
print(index.is_trained)

index.add(xb)                  # add vectors to the index
print(index.ntotal)


nq = 5                          # number of query vectors
k = 4                           # we want 4 similar vectors
Xq = np.random.random((nq, d)).astype('float32')
D, I = index.search(Xq, k)     # sanity check
print(I)
print(D)
